package be.destin.rdf.changes;

import be.destin.skos.core.Concept;
import be.destin.skos.core.ConceptScheme;
import be.destin.skos.html.SkosHtmlManager;
import be.destin.util.Util;

/* Selon Mondecca, types de modifications pour un thesaurus:
 * Add
 * Rename
 * Move
 * Merge
 * Deprecate (avec lien "use instead")
 * Split
 * Delete
 */
public enum Status {
	 New_Proposed,  New_Under_Review,  Published,  Change_Proposed,  Change_Under_Review,  Deprecate_Proposed,  Deprecate_Under_Review,  Deprecated, Not_Approved;

	public String getScheme_About() {
		return "status_"+this.toString();
	}

	public static final Power[] powerNeeded = {
		Power.Propose,
		Power.Review,
		Power.Publish,
		Power.Propose,
		Power.Review,
		Power.Propose,
		Power.Review,
		Power.Publish,
		Power.Destroy
	};
	
	private static final String[] graphVizColor = {
		"blue",
		"blue",
		"forestgreen",
		"gold",
		"gold",
		"red",
		"red",
		"red",
		"red"
	};
	
	private static final String[] arrowLabels = {
		"?",
		"!",
		" ",
		"?",
		"!",
		"?",
		"!",
		"x",
		" "
	};
	
	public static String graphVizColor(Status aStatus) {
		if (aStatus==null) return "";
		return ",color="+graphVizColor[aStatus.ordinal()];
	}

	public static String graphVizLabel(String prefix, Status aStatus) {
		if (aStatus==null) {
			if (prefix==null || prefix.isEmpty()) return "";
			aStatus = Published; // default status
		}
		if (prefix==null) prefix="";
		prefix = (prefix+' '+arrowLabels[aStatus.ordinal()]).trim();
		if (prefix.isEmpty()) return "";
		return ",label=\""+prefix+'\"';
	}

	public String toHtml(SkosHtmlManager skosHtmlManager) {
		ConceptScheme theStatuses = skosHtmlManager.getSkosManager().getStatus();
		//if (application == null) application = this.application;
		if (theStatuses == null) return this.toString();
		Concept conceptRole = theStatuses.getConcept(this.name());
		if (conceptRole == null) return this.toString();
		String label = conceptRole.getPrefLabel(skosHtmlManager.getLanguage(), false);
		if (label != null && !label.isEmpty()) label = label+":";
		String icon = conceptRole.getIconAdapted(skosHtmlManager);
		if (icon != null && !icon.isEmpty()) {
			return skosHtmlManager.toHtmlImage(icon, label, false);
		} else if (label != null) {
			return Util.escapeHTMLEntities(label);
		} else  {
			return this.toString();
		}
	}

	public static String list() {
		StringBuffer result = new StringBuffer();
		Status[] types = Status.values();
		for (int i=0; i<types.length; i++) {
			Status aType = types[i];
			result.append(aType.toString());
			if ( (i+1) < types.length) result.append(", ");
		}
		return result.toString();
	}

}
